package com.cube.springtest.aqs.S03;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author YCL
 * @version 1.0
 * @Description
 * @date 2021/7/13
 */
public class Main {
    private static Integer m =0;
    public static Lock lock = new ReentrantLock();
    public static void main(String[] args) throws InterruptedException {

        Thread[] threads = new Thread[100];
        for (int i = 0; i < threads.length; i++) {
            threads[i] = new Thread(()->{
                lock.lock();;
                for (int j = 0; j < 100; j++) {
                    m++;
                }
                lock.unlock();
            });
        }
        for (Thread t : threads) t.start();
        for (Thread t : threads) t.join();  //等待所有线程运行结束
        System.out.println(m);
    }
}
